package edu.sctu.yueding.activitys;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import edu.sctu.yueding.R;
import edu.sctu.yueding.adapter.PhotoViewPagerAdapter;
import edu.sctu.yueding.adapter.ShowPhotoViewPager;
import edu.sctu.yueding.utils.ImageLoader;
import edu.sctu.yueding.utils.httputils.GetVolleyHttp;

/**
 * Created by 鑫爷您慢点 on 2016/8/3.
 */
public class ShowSelectedPhotoActivity extends BaseActivity {
    private ViewPager mViewPager;
    private List<String> selectedImgPath;
    private boolean isURL = false;
    private int position = 0;
    private Activity mMyActivity;
    private TextView mReturnTxt, leftTxt, rightTxt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.photo_show_photo);
        mMyActivity = ShowSelectedPhotoActivity.this;
//        initSystemBar(mMyActivity);

        initView();

        setEvent();

    }

    private void setEvent() {

        mViewPager.setAdapter(new ShowPhotoViewPager(selectedImgPath, isURL, this));
        mViewPager.setCurrentItem(position);

        mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {
                if (position != 0) {
                    leftTxt.setText(position + 1 + "");
                    position = 0;
                }

            }

            @Override
            public void onPageSelected(int i) {
                if (position == 0) {
                    leftTxt.setText(i + 1 + "");
                }
            }

            @Override
            public void onPageScrollStateChanged(int i) {
            }
        });
    }

    private void initView() {

        Bundle bundle = this.getIntent().getExtras();
        isURL = bundle.getBoolean("isURL", false);
        position = bundle.getInt("position");
        selectedImgPath = bundle.getStringArrayList("selectedImgPath");

        mViewPager = (ViewPager) findViewById(R.id.id_show_photo_view_pager);
        mReturnTxt = (TextView) findViewById(R.id.id_show_photo_back_txt);

        leftTxt = (TextView) findViewById(R.id.id_show_photo_left_text);
        rightTxt = (TextView) findViewById(R.id.id_show_photo_right_text);

        rightTxt.setText("/" + selectedImgPath.size());

        mReturnTxt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}
